package com.gui.juc.base.thread.method;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class MovieDownloadDemo {

    public static void main(String[] args) throws InterruptedException {

        Thread downloadThread = new Thread(() -> {
            int progress = 0;
            while (true) {
                if (Thread.currentThread().isInterrupted()) {
                    log.debug("用户点了停止按钮，保存一下进度再停机，当前进度为：{}%", progress);
                    break;
                }
                try {
                    TimeUnit.SECONDS.sleep(1);
                    log.debug("下载电影中,当前进度为：{}%", ++progress);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }


            }
        }, "download-task");

        log.debug("开始下载电影...");
        downloadThread.start();
        TimeUnit.SECONDS.sleep(10);
        log.debug("没流量了，赶紧暂停！！！");
        downloadThread.interrupt();
    }
}
